const path = require('path');
const webpack = require('webpack');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const multipleEntry = require('./multipleEntry');

module.exports = {
    entry: multipleEntry.entries,
    resolve: {
        extensions: ['.css', '.js', '.vue'],
        modules: [
            path.resolve(__dirname, '../src'),
            path.resolve(__dirname, '../node_modules'),
        ],
        // 路径别名
        alias: {
            '@src': path.resolve(__dirname, '../src'),
            '@config': path.resolve(__dirname, '../config'),
            '@css': path.resolve(__dirname, '../src/css'),
            '@img': path.resolve(__dirname, '../src/img'),
            '@js': path.resolve(__dirname, '../src/js'),
            '@comps': path.resolve(__dirname, '../src/comps'),
            '@views': path.resolve(__dirname, '../src/views'),
        },
    },
    module: {
        rules: [{
            test: /\.js$/,
            enforce: 'pre',
            use: ['babel-loader'],
            exclude: [
                path.resolve(__dirname, '../node_modules'),
            ],
        }, {
            test: /\.vue$/,
            use: {
                loader: 'vue-loader',
                options: {
                    hotReload: true,
                },
            },
            exclude: [
                path.resolve(__dirname, '../node_modules'),
            ],
        }, {
            test: /\.(png|jpg|jpeg|gif|svg)$/,
            use: {
                loader: 'url-loader',
                options: {
                    limit: 2048,
                    name: '[name].[ext]',
                    outputPath: 'img/',
                    publicPath: '../img', // dev和 production css中文件的路径: '../img/[name].[ext]'
                },
            },
            exclude: [
                path.resolve(__dirname, '../node_modules'),
            ],
        },
        {
            test: /\.(woff|woff2|ttf|eot)$/,
            use: {
                loader: 'url-loader',
                options: {
                    limit: 2048,
                    name: '[name].[ext]',
                    outputPath: 'fonts/',
                    publicPath: '../fonts',
                },
            },
            exclude: [
                path.resolve(__dirname, '../node_modules'),
            ],
        }],
    },
    plugins: [
        new FriendlyErrorsWebpackPlugin(),
        new webpack.HashedModuleIdsPlugin(),
        new webpack.optimize.ModuleConcatenationPlugin(),
    ],
    node: {
        // prevent webpack from injecting useless setImmediate polyfill because Vue
        // source contains it (although only uses it if it's native).
        setImmediate: false,
        // prevent webpack from injecting mocks to Node native modules
        // that does not make sense for the client
        dgram: 'empty',
        fs: 'empty',
        net: 'empty',
        tls: 'empty',
        child_process: 'empty'
    }
};
